﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuickLifeHall.ERP.Utilities
{
    public class HttpUtilities
    {
        /// <summary>
        /// 返回Json数据，并结束本次回应
        /// </summary>
        /// <param name="response"></param>
        /// <param name="obj"></param>
        public static void ResponseJsonString(HttpResponse response, object obj)
        {
            response.ContentType = "text/json";
            response.Write(Core.Util.SerializeToJson(obj));
            response.Flush();
            response.End();
        }

        /// <summary>
        /// 获取Request的参数，并转换为指定类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="request"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T GetRequestParam<T>(HttpRequest request, string key)
        {
            string value = request[key];
            return (T)Core.Util.ChangeType(value, typeof(T));
        }
    }
}